﻿using Microsoft.Extensions.DependencyInjection;
namespace MingYuanYun.WebApi.Cors
{
    public static class CorsExtensions
    {
        //public static IApplicationBuilder UseCors(this IApplicationBuilder app)
        //{
        //    // Use cors config
        //    app.UseCors(CorsOptions.PolicyName);

        //    return app;
        //}

        public static IServiceCollection AddCors(this IServiceCollection services, CorsOptions options)
        {
            // Config the cors options.
            services.AddCors(opt => opt.AddPolicy(CorsOptions.PolicyName,
                builder => builder.WithOrigins(options.CorsOrigins)
                    .AllowCredentials()
                    .AllowAnyHeader()
                    .AllowAnyMethod()));

            return services;
        }
    }
}
